package threading;

//懒汉模式(单线程)
//class  SingletonLazy {
//    private static SingletonLazy instance = null;
//
//    public static SingletonLazy getSingletonLazy() {
//        if (instance == null) {
//            instance = new SingletonLazy();
//        }
//        return instance;
//    }
//    private SingletonLazy() {
//
//    }
//}
class SingletonLazy{
    volatile private static SingletonLazy  singletonLazy = null;

    public static SingletonLazy getSingletonLazy() {
        if (singletonLazy == null) {
            synchronized (SingletonLazy.class) {
               if (singletonLazy == null) {
                   singletonLazy = new SingletonLazy();
               }
            }

        }
        return singletonLazy;
    }

    private  SingletonLazy() {

    }
}
public class ThreadDemo19 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getSingletonLazy();
        SingletonLazy s2 = SingletonLazy.getSingletonLazy();
        System.out.println(s1 == s2);
    }
}
